<?php
/**
 * 工程开工令
 * @author YangL
 **/
namespace Admin\Controller;
use Common\Controller\WahahabaseController;
class ConstructionCommandController extends WahahabaseController{
	
	public function _initialize() {
		parent::_initialize();
		$this->deal_model = D("Common/ConstructionCommand");
		$this->att_model = D("Common/Attachment");
		$this->dept_model = D("Common/Department");
		$this->check = array('code', 'command_type');
	}
	
	
	/**
     * 工程开工令 
     */
	public function gcstart(){
		$where = array("d.is_deleted"=>array('neq', 1));
		$where['command_type'] = 1;
		$title = trim(I('request.title'));
		if($title){
			$where['title'] = array('like',"%$title%");
		}
		$this->getDepartLevel();
		$this->indexPage($where);
		
		
//		$count=$this->deal_model->alias("n")->where($where)->count();
//		$page = $this->page($count, 20);
//		
//		$results = $this->deal_model->alias("n")
//			->field('n.*,u.real_name')
//			->join(array(
//				' LEFT JOIN '.C('DB_PREFIX').'users u ON n.add_user = u.id',
//			))
//            ->where($where)
//            ->order("n.add_time DESC")
//            ->limit($page->firstRow, $page->listRows)
//            ->select();
//			
//		$this->assign("page", $page->show('Admin'));
//		$this->assign("results",$results);
//		
//		$this->display();
	}
	public function gcstart_add(){
		$depts = $this->dept_model->field("id,department_name")->where(array('is_deleted' => array('neq', 1),'department_role' => 5))->select();
		$this->assign("depts", $depts);
		//var_dump($depts);
		$this->display();
	}
	public function gcstart_add_post(){
		$this->addFilePost(U("ConstructionCommand/gcstart"), 8);
	}
	public function gcstart_edit(){
		$depts = $this->dept_model->field("id,department_name")->where(array('is_deleted' => array('neq', 1),'department_role' => 5))->select();
		$this->assign("depts", $depts);
		$this->editFileDisplay(8);
	}
	public function gcstart_edit_post(){
		$this->editFilePost(U("ConstructionCommand/gcstart"), 8);
	}
    public function  gcstart_view(){
		 $id = I('get.id',0,'intval');
		 $data=$this->deal_model->where(array("id"=>$id))->find();
         $this->assign("result",$data);
		 $results = $this->att_model->where(array("table_id"=>$id, "belong_to"=>8))->select();
		 $this->assign("results", $results);
		 $this->getDepartLevel();
         $this->display();
	}
	public function gcstart_delete(){
		$this->delete();
	}

	/**
     * 工程暂停令 
     */
	public function gcpause(){
		$where = array("d.is_deleted"=>array('neq', 1));
		$where['command_type'] = 2;
		$title = trim(I('request.title'));
		if($title){
			$where['title'] = array('like',"%$title%");
		}
        $this->getDepartLevel();
		$this->indexPage($where);
		
		//总条数
//		$count=$this->deal_model->alias("n")->where($where)->count();
//		$page = $this->page($count, 20);
//		
//		$results = $this->deal_model->alias("n")
//			->field('n.*,u.real_name')
//			->join(array(
//				' LEFT JOIN '.C('DB_PREFIX').'users u ON n.add_user = u.id',
//			))
//            ->where($where)
//            ->order("n.add_time DESC")
//            ->limit($page->firstRow, $page->listRows)
//            ->select();
//		
//		$this->assign("page", $page->show('Admin'));
//		$this->assign("results",$results);
//		
//		$this->display();
	}
	public function gcpause_add(){
		$this->display();
	}
	public function gcpause_add_post(){
		if(IS_POST){
			$this->dataCheck();
			$data = array_merge($_POST, $this->saveData());
			if ($this->deal_model->create()!==false) {
				$result = $this->deal_model->add($data);
				if ($result!==false) {				
					$this->success("添加成功！", U("ConstructionCommand/gcpause"));
				} else {
					$this->error("添加失败！");
				}
			} else {
				$this->error($this->deal_model->getError());
			}
		}
	}
	public function gcpause_edit(){
		$id = I('get.id',0,'intval');
		$result = $this->deal_model->where(array("id"=>$id))->find();
		
		$this->assign("result", $result);
		
		$this->display();
	}
	public function gcpause_edit_post(){
		if (IS_POST) {
			$this->dataCheck();
			$data = array_merge($_POST, $this->saveData(2));
			if ($this->deal_model->create()!==false) {
				$result=$this->deal_model->save($data);
				if ($result !== false) {
					$this->success("保存成功！", U("ConstructionCommand/gcpause"));
				} else {
					$this->error("保存失败！");
				}
			} else {
				$this->error($this->deal_model->getError());
			}
		}
	}
    public function  gcpause_view(){
		 $id = I('get.id',0,'intval');
		$result = $this->deal_model->where(array("id"=>$id))->find();
		
		$this->assign("result", $result);
		$this->getDepartLevel();
		$this->display();
	}
	public function gcpause_delete(){
		$this->delete();
	}

	/**
     * 工程复工令 
     */
	public function gcrestart(){
		$where = array("d.is_deleted"=>array('neq', 1));
		$where['command_type'] = 3;
		$title = trim(I('request.title'));
		if($title){
			$where['title'] = array('like',"%$title%");
		}
		$this->getDepartLevel();
		$this->indexPage($where);
		
		//总条数
//		$count=$this->deal_model->alias("n")->where($where)->count();
//		$page = $this->page($count, 20);
//		
//		$results = $this->deal_model->alias("n")
//			->field('n.*,u.real_name')
//			->join(array(
//				' LEFT JOIN '.C('DB_PREFIX').'users u ON n.add_user = u.id',
//			))
//            ->where($where)
//            ->order("n.add_time DESC")
//            ->limit($page->firstRow, $page->listRows)
//            ->select();
//			
//		$this->assign("page", $page->show('Admin'));
//		$this->assign("results",$results);
//				
//		$this->display();
	}
	public function gcrestart_add(){
		$this->display();
	}
	public function gcrestart_add_post(){
		if(IS_POST){
			$this->dataCheck();
			$data = array_merge($_POST, $this->saveData());
			if ($this->deal_model->create()!==false) {
				$result = $this->deal_model->add($data);
				if ($result!==false) {	
					$this->saveFile($result, 9, 2);				
					$this->success("添加成功！", U("ConstructionCommand/gcrestart"));
				} else {
					$this->error("添加失败！");
				}
			} else {
				$this->error($this->deal_model->getError());
			}
		}
	}
	public function gcrestart_edit(){
		$id = I('get.id',0,'intval');
		$result = $this->deal_model->where(array("id"=>$id))->find();
		$this->assign("result", $result);
		
		$results = $this->att_model->where(array("table_id"=>$id, "belong_to"=>9))->select();
		$this->assign("results", $results);
		
		$this->display();
	}
	    public function  gcrestart_view(){
		 $id = I('get.id',0,'intval');
		 $data=$this->deal_model->where(array("id"=>$id))->find();
         $this->assign("result",$data);
         $results = $this->att_model->where(array("table_id"=>$id, "belong_to"=>9))->select();
		 $this->assign("results", $results);
		 $this->getDepartLevel();
         $this->display();
	}
	public function gcrestart_edit_post(){
		if (IS_POST) {
			$this->dataCheck();
			$data = array_merge($_POST, $this->saveData(2));
			$data['begin_construction_time'] = $data["year"].'-'.$data['month'].'-'.$data['day'].'-'.$data['hour'];
			if ($this->deal_model->create()!==false) {
				$result=$this->deal_model->save($data);
				if ($result !== false) {
					$this->saveFile(I("post.id"), 9, 2);
					$this->success("保存成功！", U("ConstructionCommand/gcrestart"));
				} else {
					$this->error("保存失败！");
				}
			} else {
				$this->error($this->deal_model->getError());
			}
		}
	}
	public function gcrestart_delete(){
		$this->delete();
	}
}


?>